#pragma once

#include "mono/Converter.h"

namespace mono
{

    template <>
    struct Converter<int>
    {
        bool Encode(void *&arg, const int &t)
        {
            const void *ptr = &t;
            memcpy(&arg, &ptr, sizeof(void *));
            return true;
        };

        bool Decode(MonoObject *object, int &t)
        {
            t = *(int *)mono_object_unbox(object);
            return true;
        }
    };

    template <>
    struct Converter<std::string>
    {
        bool Encode(void *&arg, const std::string &t)
        {
            arg = mono_string_new(mono_domain_get(), t.c_str());
            return true;
        }

        bool Decode(MonoObject *object, std::string &t)
        {
            bool res = (mono_object_get_class(object) == mono_get_string_class());

            if (res)
                t = mono_string_to_utf8((MonoString *)object);
            return res;
        };
    };

    template <>
    struct Converter<float>
    {
        bool Decode(MonoObject *object, float &t)
        {
            t = *(float *)mono_object_unbox(object);
            return true;
        }
        bool Encode(void *&arg, const float &t)
        {
            const void *ptr = &t;
            memcpy(&arg, &ptr, sizeof(void *));
            return true;
        }
    };
};